package com.programmingteam.wallpaperslideshow.ui.fragments;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.programmingteam.wallpaperslideshow.PlaceSelectorView;
import com.programmingteam.wallpaperslideshow.R;
import com.programmingteam.wallpaperslideshow.ui.GalleryActivity;
import com.programmingteam.wallpaperslideshow.ui.PrefsActivity;

public class DashboardFragment extends Fragment {

	public DashboardFragment() {
		super();
	}

	public void fireTrackerEvent(String label) {
		// AnalyticsUtils.getInstance(getActivity()).trackEvent(
		// "Home Screen Dashboard", "Click", label, 0);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View root = inflater.inflate(R.layout.fragment_dashboard, container);

		// Attach event handlers
		root.findViewById(R.id.dash_btn_recent).setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				fireTrackerEvent("Schedule");
				getActivity().startActivity(new Intent(getActivity(), GalleryActivity.class));
			}

		});

		root.findViewById(R.id.dash_btn_places).setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				fireTrackerEvent("Sessions");
				getActivity().startActivity(new Intent(getActivity(), PlaceSelectorView.class));
			}
		});

		root.findViewById(R.id.dash_btn_favourites).setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				fireTrackerEvent("Starred");
				getActivity().startActivity(new Intent(getActivity(), GalleryActivity.class));
			}
		});

		root.findViewById(R.id.dash_btn_help).setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				DialogFragment newFragment = AlertDialogFragment.newInstance(1);
			    newFragment.show(getFragmentManager(), "dialog");
				fireTrackerEvent("Sandbox");
			}
		});

		root.findViewById(R.id.dash_btn_preferences).setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				// Launch map of conference venue
				fireTrackerEvent("Map");
				Intent i = new Intent(getActivity().getApplicationContext(), PrefsActivity.class);
				startActivity(i);
			}
		});

		root.findViewById(R.id.dash_btn_more).setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				// Launch market with more apps	
				fireTrackerEvent("Bulletin");
				Intent i = new Intent(Intent.ACTION_VIEW);
				i.setData(Uri.parse("market://search?q=pub:\"ProgrammingTeam\""));
				startActivity(i);
			}
		});

		return root;
	}
}
